home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / test / menubar.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-26  |  6.9 KB  |  219 lines

  1. //
  2. // "$Id: menubar.cxx,v 1.6.2.1 1999/04/26 06:45:29 bill Exp $"
  3. //
  4. // Menubar test program for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. #include <FL/Fl.H>
  27. #include <FL/Fl_Box.H>
  28. #include <FL/Fl_Window.H>
  29. #include <FL/Fl_Menu_Bar.H>
  30. #include <FL/Fl_Toggle_Button.H>
  31. #include <FL/Fl_Menu_Button.H>
  32. #include <FL/Fl_Choice.H>
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #include <FL/fl_draw.H>
  37.  
  38. void test_cb(Fl_Widget* w, void*) {
  39.   Fl_Menu_* mw = (Fl_Menu_*)w;
  40.   const Fl_Menu_Item* m = mw->mvalue();
  41.   if (!m)
  42.     printf("NULL\n");
  43.   else if (m->shortcut())
  44.     printf("%s - %s\n", m->label(), fl_shortcut_label(m->shortcut()));
  45.   else
  46.     printf("%s\n", m->label());
  47. }
  48.  
  49. void quit_cb(Fl_Widget*, void*) {exit(0);}
  50.  
  51. Fl_Menu_Item hugemenu[100];
  52.  
  53. Fl_Menu_Item menutable[] = {
  54.   {"foo",0,0,0,FL_MENU_INACTIVE},
  55.   {"&File",0,0,0,FL_SUBMENU},
  56.     {"&Open",    FL_ALT+'o', 0, 0, FL_MENU_INACTIVE},
  57.     {"&Close",    0,    0},
  58.     {"&Quit",    FL_ALT+'q', quit_cb, 0, FL_MENU_DIVIDER},
  59.     {"shortcut",'a'},
  60.     {"shortcut",FL_SHIFT+'a'},
  61.     {"shortcut",FL_CTRL+'a'},
  62.     {"shortcut",FL_CTRL+FL_SHIFT+'a'},
  63.     {"shortcut",FL_ALT+'a'},
  64.     {"shortcut",FL_ALT+FL_SHIFT+'a'},
  65.     {"shortcut",FL_ALT+FL_CTRL+'a'},
  66.     {"shortcut",FL_ALT+FL_SHIFT+FL_CTRL+'a', 0,0, FL_MENU_DIVIDER},
  67.   {"shortcut",'\r'/*FL_Enter*/},
  68.     {"shortcut",FL_CTRL+FL_Enter, 0,0, FL_MENU_DIVIDER},
  69.     {"shortcut",FL_F+1},
  70.     {"shortcut",FL_SHIFT+FL_F+1},
  71.     {"shortcut",FL_CTRL+FL_F+1},
  72.     {"shortcut",FL_SHIFT+FL_CTRL+FL_F+1},
  73.     {"shortcut",FL_ALT+FL_F+1},
  74.     {"shortcut",FL_ALT+FL_SHIFT+FL_F+1},
  75.     {"shortcut",FL_ALT+FL_CTRL+FL_F+1},
  76.     {"shortcut",FL_ALT+FL_SHIFT+FL_CTRL+FL_F+1, 0,0, FL_MENU_DIVIDER},
  77.     {"&Submenus", FL_ALT+'S',    0, (void*)"Submenu1", FL_SUBMENU},
  78.       {"A very long menu item"},
  79.       {"&submenu",FL_CTRL+'S',    0, (void*)"submenu2", FL_SUBMENU},
  80.     {"item 1"},
  81.     {"item 2"},
  82.     {"item 3"},
  83.     {"item 4"},
  84.     {0},
  85.       {"after submenu"},
  86.       {0},
  87.     {0},
  88.   {"&Edit",0,0,0,FL_SUBMENU},
  89.     {"Undo",    FL_ALT+'z',    0},
  90.     {"Redo",    FL_ALT+'r',    0, 0, FL_MENU_DIVIDER},
  91.     {"Cut",    FL_ALT+'x',    0},
  92.     {"Copy",    FL_ALT+'c',    0},
  93.     {"Paste",    FL_ALT+'v',    0},
  94.     {"Inactive",FL_ALT+'d',    0, 0, FL_MENU_INACTIVE},
  95.     {"Clear",    0,    0, 0, FL_MENU_DIVIDER},
  96.     {"Invisible",FL_ALT+'e',    0, 0, FL_MENU_INVISIBLE},
  97.     {"Preferences",0,    0},
  98.     {"Size",    0,    0},
  99.     {0},
  100.   {"&Checkbox",0,0,0,FL_SUBMENU},
  101.     {"&Alpha",    FL_F+2,    0, (void *)1, FL_MENU_TOGGLE},
  102.     {"&Beta",    0,    0, (void *)2, FL_MENU_TOGGLE},
  103.     {"&Gamma",    0,    0, (void *)3, FL_MENU_TOGGLE},
  104.     {"&Delta",    0,    0, (void *)4, FL_MENU_TOGGLE|FL_MENU_VALUE},
  105.     {"&Epsilon",0,    0, (void *)5, FL_MENU_TOGGLE},
  106.     {"&Pi",    0,    0, (void *)6, FL_MENU_TOGGLE},
  107.     {"&Mu",    0,    0, (void *)7, FL_MENU_TOGGLE|FL_MENU_DIVIDER},
  108.     {"Red",    0,    0, (void *)1, FL_MENU_TOGGLE, 0, 0, 0, 1},
  109.     {"Black",    0,    0, (void *)1, FL_MENU_TOGGLE|FL_MENU_DIVIDER},
  110.     {"00",    0,    0, (void *)1, FL_MENU_TOGGLE},
  111.     {"000",    0,    0, (void *)1, FL_MENU_TOGGLE},
  112.     {0},
  113.   {"&Radio",0,0,0,FL_SUBMENU},
  114.     {"&Alpha",    0,    0, (void *)1, FL_MENU_RADIO},
  115.     {"&Beta",    0,    0, (void *)2, FL_MENU_RADIO},
  116.     {"&Gamma",    0,    0, (void *)3, FL_MENU_RADIO},
  117.     {"&Delta",    0,    0, (void *)4, FL_MENU_RADIO|FL_MENU_VALUE},
  118.     {"&Epsilon",0,    0, (void *)5, FL_MENU_RADIO},
  119.     {"&Pi",    0,    0, (void *)6, FL_MENU_RADIO},
  120.     {"&Mu",    0,    0, (void *)7, FL_MENU_RADIO|FL_MENU_DIVIDER},
  121.     {"Red",    0,    0, (void *)1, FL_MENU_RADIO},
  122.     {"Black",    0,    0, (void *)1, FL_MENU_RADIO|FL_MENU_DIVIDER},
  123.     {"00",    0,    0, (void *)1, FL_MENU_RADIO},
  124.     {"000",    0,    0, (void *)1, FL_MENU_RADIO},
  125.     {0},
  126.   {"&Font",0,0,0,FL_SUBMENU /*, 0, FL_BOLD, 20*/},
  127.     {"Normal",    0, 0, 0, 0, 0, 0, 14},
  128.     {"Bold",    0, 0, 0, 0, 0, FL_BOLD, 14},
  129.     {"Italic",    0, 0, 0, 0, 0, FL_ITALIC, 14},
  130.     {"BoldItalic",0,0,0, 0, 0, FL_BOLD+FL_ITALIC, 14},
  131.     {"Small",    0, 0, 0, 0, 0, FL_BOLD+FL_ITALIC, 10},
  132.     {"Emboss",    0, 0, 0, 0, FL_EMBOSSED_LABEL},
  133.     {"Engrave",    0, 0, 0, 0, FL_ENGRAVED_LABEL},
  134.     {"Shadow",    0, 0, 0, 0, FL_SHADOW_LABEL},
  135.     {"@->",    0, 0, 0, 0, FL_SYMBOL_LABEL},
  136.     {0},
  137.   {"E&mpty",0,0,0,FL_SUBMENU},
  138.     {0},
  139.   {"&Inactive", 0,    0, 0, FL_MENU_INACTIVE|FL_SUBMENU},
  140.     {"A very long menu item"},
  141.     {"A very long menu item"},
  142.     {0},
  143.   {"Invisible",0,    0, 0, FL_MENU_INVISIBLE|FL_SUBMENU},
  144.     {"A very long menu item"},
  145.     {"A very long menu item"},
  146.     {0},
  147.   {"&Huge", 0, 0, (void*)hugemenu, FL_SUBMENU_POINTER},
  148.   {"button",0, 0, 0, FL_MENU_TOGGLE},
  149.   {0}
  150. };
  151.  
  152. Fl_Menu_Item pulldown[] = {
  153.   {"Red",    FL_ALT+'r'},
  154.   {"Green",    FL_ALT+'g'},
  155.   {"Blue",    FL_ALT+'b'},
  156.   {"Strange",    FL_ALT+'s'},
  157.   {"&Charm",    FL_ALT+'c'},
  158.   {"Truth",    FL_ALT+'t'},
  159.   {"Beauty",    FL_ALT+'b'},
  160.   {0}
  161. };
  162.  
  163. #define WIDTH 600
  164.  
  165. Fl_Menu_* menus[4];
  166.  
  167. // turn MicroSoft style on/off
  168. void button_cb(Fl_Widget* w, void*) {
  169.   if (((Fl_Button*)w)->value()) {
  170.     for (int i = 0; i < 4; i++) {
  171.       menus[i]->down_box(FL_FLAT_BOX);
  172.       menus[i]->selection_color(137);
  173.       menus[i]->textfont(FL_HELVETICA);
  174.     }
  175.   } else {
  176.     for (int i = 0; i < 4; i++) {
  177.       menus[i]->down_box(FL_NO_BOX);
  178.       menus[i]->selection_color(FL_WHITE);
  179.       menus[i]->textfont(FL_BOLD|FL_ITALIC);
  180.     }
  181.   }
  182.   menus[0]->parent()->redraw();
  183. }
  184.  
  185. int main(int argc, char **argv) {
  186.   for (int i=0; i<99; i++) {
  187.     char buf[100];
  188.     sprintf(buf,"item %d",i);
  189.     hugemenu[i].text = strdup(buf);
  190.   }
  191.   Fl_Window window(WIDTH,400);
  192.   Fl_Menu_Bar menubar(0,0,WIDTH,30); menubar.menu(menutable);
  193.   menubar.callback(test_cb);
  194.   menus[0] = &menubar;
  195.   Fl_Menu_Button mb1(100,100,120,25,"&menubutton"); mb1.menu(pulldown);
  196.   mb1.callback(test_cb);
  197.   menus[1] = &mb1;
  198.   Fl_Choice ch(300,100,80,25,"&choice:"); ch.menu(pulldown);
  199.   ch.callback(test_cb);
  200.   menus[2] = &ch;
  201.   Fl_Menu_Button mb(0,0,WIDTH,400,"&popup");
  202.   mb.type(Fl_Menu_Button::POPUP3);
  203.   mb.menu(menutable);
  204.   mb.callback(test_cb);
  205.   menus[3] = &mb;
  206.   Fl_Box b(200,200,200,100,"Press right button\nfor a pop-up menu");
  207.   Fl_Toggle_Button t(250,50,150,25,"MicroSoft Style");
  208.   t.callback(button_cb);
  209.   window.resizable(&mb);
  210.   window.size_range(300,20);
  211.   window.end();
  212.   window.show(argc, argv);
  213.   return Fl::run();
  214. }
  215.  
  216. //
  217. // End of "$Id: menubar.cxx,v 1.6.2.1 1999/04/26 06:45:29 bill Exp $".
  218. //
  219.